package net.oschina.app.fragment.center_message;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.chanven.lib.cptr.recyclerview.RecyclerAdapterWithHF;

import net.oschina.app.adapter.center_message.AtMeAdapter;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.base.BaseFragment;
import net.oschina.app.bean.ActiveBean;
import net.oschina.app.bean.CallMeBean;
import net.oschina.app.interf.FragmentType;
import net.oschina.app.protocol.me_messager.AtMeAndCommentProtocol;
import net.oschina.app.ui.DetailFragmentActivity;
import net.oschina.app.util.CommonUtils;

import java.util.List;

/**
 * Created by wei03 on 2017/1/13.
 */
public class AtMeFragment extends BaseFragment<CallMeBean> {

    private AtMeAdapter mAtMeAdapter;
    private List<ActiveBean> mActivies;


    @Override
    protected void OnSubItemClick(RecyclerAdapterWithHF adapter, RecyclerView.ViewHolder vh, int position) {
        ActiveBean activeBean = mActivies.get(position);
        Intent intent = new Intent(CommonUtils.getContext(), DetailFragmentActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("bean",activeBean);
        intent.putExtras(bundle);
        intent.putExtra(FragmentType.FRAGMENT_TYPE,FragmentType.TYPE_ME_ATME_DETAIL);
        startActivity(intent);
    }

    @Override
    protected int onLoadSubData() {
        Bundle arguments = getArguments();
        String catalog = "";
        if (arguments != null) {
            catalog = arguments.getString("catalog");
        }
        AtMeAndCommentProtocol atMeProtocol = new AtMeAndCommentProtocol(catalog);
        final CallMeBean callMeBean = atMeProtocol.getData(mList.size() / 2);
        if (callMeBean != null) {
            CommonUtils.runOnMainThread(new Runnable() {
                @Override
                public void run() {
                    if (mAtMeAdapter != null) {
                        mActivies = callMeBean.getActivies();
                        mAtMeAdapter.setDatas(mActivies);
                    }
                }
            });
            return STATE_SUCCESS;
        }
        return STATE_EMPTY;
    }

    @Override
    protected BaseAdapter getRvAdapter() {
        mAtMeAdapter = new AtMeAdapter();
        return mAtMeAdapter;
    }
}
